package cn.edu.hunau.java.week01.day03;

import org.junit.Test;

import java.util.Arrays;
import java.util.Random;

public class SufferArrayTest {

    @Test
    public void test01(){
        int [] arr=new int[20];
        for(int i=0;i<arr.length;i++){
            arr[i]=i+1000;
        }
        System.out.println(Arrays.toString(arr));
        suffer(arr);
        System.out.println(Arrays.toString(arr));
    }
    public void suffer(int[] arr){
        Random r=new Random();
        for(int i=arr.length-1;i>0;i--){
            int j=r.nextInt(i);
            change(arr,i,j);
        }
    }

    private void change(int[] arr, int i, int j) {
        int temp=arr[i];
        arr[i]=arr[j];
        arr[j]=temp;
    }
}
